
# 生成protobuf代码
file(GLOB_RECURSE PROTO_FILES ${CMAKE_SOURCE_DIR}/zeroplusmq/network/protocol/*.proto)
set(PROTO_SOURCE "")
set(PROTO_HEADER "")
foreach(msg ${PROTO_FILES})
    get_filename_component(PREFIX ${msg} NAME_WE)

    list(APPEND PROTO_SOURCE "${CMAKE_SOURCE_DIR}/zeroplusmq/network/protocol/${PREFIX}.pb.cc")
    list(APPEND PROTO_HEADER "${CMAKE_SOURCE_DIR}/zeroplusmq/network/protocol/${PREFIX}.pb.h")

    # add_custom_command(
    #         OUTPUT "${CMAKE_SOURCE_DIR}/zeroplusmq/protocol/${PREFIX}.pb.cc"
    #                 "${CMAKE_SOURCE_DIR}/zeroplusmq/protocol/${PREFIX}.pb.h"
    #         COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
    #         ARGS -I ${CMAKE_SOURCE_DIR}/zeroplusmq/protocol/
    #              --cpp_out ${CMAKE_SOURCE_DIR}/zeroplusmq/protocol/
    #              ${msg}
    #         DEPENDS ${msg}
    #         COMMENT "Running C++ protocol buffer compiler on ${msg}"
    #         VERBATIM
    #         )
endforeach()
# 设置文件属性为 GENERATED
# set_source_files_properties(${PROTO_SOURCE} ${PROTO_HEADER} PROPERTIES GENERATED TRUE)
# 添加自定义target
# add_custom_target(
#     generate_message ALL
#     DEPENDS ${PROTO_SOURCE} ${PROTO_HEADER}
#     COMMENT "generate message target"
#     VERBATIM
# )


set(SRC
    ${PROTO_SOURCE}
    # 基础库
    base/Bytes.cpp
    base/MessageLoop.cpp
    base/Timer.cpp
    base/Message.cpp
    # 消息模型
    network/model/PublisherNode.cpp
    network/model/SubscriberNode.cpp
    network/model/ClientNode.cpp
    network/model/ServerNode.cpp
    # 网络API封装
    network/connection/ZmqConnection.cpp
    # 生产者组件
    component/producer/ProducerController.cpp
    component/producer/client/MessagePublisher.cpp
    component/producer/client/RouteInfoDownloader.cpp
    component/producer/client/RouteInfoSelector.cpp
    # 消费者组件
    component/consumer/client/MessageSubscriber.cpp
    component/consumer/client/RouteInfoDownloader.cpp
    component/consumer/client/RouteInfoSelector.cpp
    component/consumer/ConsumerController.cpp
    # broker组件
    component/broker/server/BrokerMediator.cpp
    component/broker/server/RequestProcessor.cpp
    component/broker/client/RouteInfoUploader.cpp
    component/broker/BrokerController.cpp
    # 路由中心组件
    component/nameserver/NameSrvController.cpp
    component/nameserver/RouteInfoManager.cpp
    # Topic管理组件
    component/admin/client/RouteInfoDownloader.cpp
    component/admin/client/TopicManager.cpp
    component/admin/TopicController.cpp
    # 存储模块
    store/RedisStore.cpp
    store/queue/DeadLetterQueue.cpp
    store/queue/DelayQueue.cpp
    store/queue/MessageQueue.cpp
    # 工具模块
    utils/utils.cpp
)

add_library(zeroplusmq SHARED ${SRC})
target_link_libraries(zeroplusmq ${LIBS})
install(TARGETS zeroplusmq DESTINATION lib)